#ifndef _best_core_log_h_
#define _best_core_log_h_

#include "pub.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifndef __LOG_DEBUT
#define __LOG_DEBUG // 注释掉将关闭日志输出
#endif              // __LOG_DEBUT

#ifdef __LOG_DEBUG
#define DEBUG(format, ...) printf(format, ##__VA_ARGS__)
#else
#define DEBUG(format, ...)
#endif

typedef enum {
    E_LOGLEVEL_OFF = 0,
    E_LOGLEVEL_FATAL,
    E_LOGLEVEL_ERR,
    E_LOGLEVEL_WARN,
    E_LOGLEVEL_INFO,
    E_LOGLEVEL_DEBUG,
} E_LOGLEVEL_TYPE;

extern E_LOGLEVEL_TYPE g_LogLevel;
// E_LOGLEVEL_TYPE g_LogLevel = E_LOGLEVEL_OFF; // move to log src

BEST_VOID CORE_LogWrite(const char *filePath, const char *fileName, int lines,
                        const char *function, const char *format, ...);

#define CORE_LogFatalWriteToFile(format, ...)                                  \
    do {                                                                       \
        CORE_LogWrite("runlog.log", __FILE__, __LINE__, __FUNCTION__, format,  \
                      ##__VA_ARGS__);                                          \
    } while (0)

#define CORE_LogFatal(format, ...)                                             \
    do {                                                                       \
        if (g_LogLevel >= E_LOGLEVEL_FATAL) {                                  \
            DEBUG("\n[FATAL](%s:%d Func:%s) " format "\n", __FILE__, __LINE__, \
                  __FUNCTION__, ##__VA_ARGS__);                                \
        }                                                                      \
    } while (0)

#define CORE_LogErr(format, ...)                                               \
    do {                                                                       \
        if (g_LogLevel >= E_LOGLEVEL_ERR) {                                    \
            DEBUG("\n[ERROR](%s:%d Func:%s) " format "\n", __FILE__, __LINE__, \
                  __FUNCTION__, ##__VA_ARGS__);                                \
        }                                                                      \
    } while (0)
#define CORE_LogWarn(format, ...)                                              \
    do {                                                                       \
        if (g_LogLevel >= E_LOGLEVEL_WARN) {                                   \
            DEBUG("\n[WARN](%s:%d Func:%s) " format "\n", __FILE__, __LINE__,  \
                  __FUNCTION__, ##__VA_ARGS__);                                \
        }                                                                      \
    } while (0)
#define CORE_LogInfo(format, ...)                                              \
    do {                                                                       \
        if (g_LogLevel >= E_LOGLEVEL_INFO) {                                   \
            DEBUG("\n[INFO](%s:%d Func:%s) " format "\n", __FILE__, __LINE__,  \
                  __FUNCTION__, ##__VA_ARGS__);                                \
        }                                                                      \
    } while (0)
#define CORE_LogDebug(format, ...)                                             \
    do {                                                                       \
        if (g_LogLevel >= E_LOGLEVEL_DEBUG) {                                  \
            DEBUG("\n[DEBUG](%s:%d Func:%s) " format "\n", __FILE__, __LINE__, \
                  __FUNCTION__, ##__VA_ARGS__);                                \
        }                                                                      \
    } while (0)

#ifdef __cplusplus
}
#endif
#endif
